package com.kins.common.entity;

import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.micrometer.common.util.StringUtils;
import lombok.Data;

import java.util.Date;


/**
 * @Description:
 * @Author: 申科
 * @Date:2025/11/12 10:15
 */
@Data
public class KinsBaseEntity<T> {

    @TableId
    @JsonSerialize(using= ToStringSerializer.class)
    private String id;
    private String createBy;
    private String createDate;
    private String updateBy;
    private String updateDate;
    private String deleteFlag;

    private String tenantId;

    @TableField(exist =false)
    public int pageNum = 0;

    @TableField
    public int pageSize = 10;

    @TableField(exist =false)
    public String orderBy;

    public boolean getIsNewRecord(){
        return StringUtils.isEmpty(this.id);
    }
    public void preInsert(String userName){
        this.setId(IdWorker.getId()+"");
        this.setCreateDate(new Date());
        this.setUpdateDate(new Date());
        this.setCreateBy(new Date());
        this.setUpdateBy(userName);
        this.setDeleteFlag(0);


    }

    public void preUpdate(String userName){
        this.setUpdateDate(new Date());
        this.setUpdateBy(userName);
    }
}
